"""CreateOrderTable Migration."""

from masoniteorm.migrations import Migration


class CreateOrderTable(Migration):
    def up(self):
        """
        Run the migrations.
        """
        with create("orders") as table:
            table.increments("id")
            table.string("order_number").unique().comment("订单编号，唯一")
            table.integer("uid").unsigned().comment("下单用户ID")
            table.foreign("uid").references("id").on("users").on_delete("cascade")
            table.decimal("total_amount", 10, 2).comment("订单总金额")
            table.enum("status", ["pending", "paid", "shipped", "completed", "cancelled"]).comment("订单状态")
            table.datetime("pay_time").nullable().comment("支付时间")
            table.enum("payment_method", ["cash", "wechat", "alipay"]).comment('支付方式')
            table.datetime("service_time").nullable().comment("服务时间")
            table.integer("address_id").unsigned().comment("服务地址ID")
            table.foreign("address_id").references("id").on("addresses")
            table.text("remark").nullable().comment("订单备注")
            table.timestamps()

    def down(self):
        """
        Revert the migrations.
        """
        self.schema.drop("orders")
